﻿@using Eqwww.Code
@model Eqwww.Web.Areas.SystemManage.Models.User.IndexViewModel
@{
    ViewData["Title"] = "用户列表";
    Layout = "~/Views/Shared/_ManageIndexLayout.cshtml";
}

<style type="text/css">
    .mdui-table td, .mdui-table th {
        padding: 8px 10px;
        line-height: 20px;
    }
</style>

<div id="eq-operate">
    <div class="mdui-appbar mdui-appbar-fixed mdui-color-white mdui-shadow-1">
        <div class="mdui-toolbar">
            <a class="eq-operate-cancel-select" href="javascript:;" mdui-tooltip="{content: '取消选择'}">
                已选中 <b>1</b> 项
            </a>

            <module-buttons class="mdui-btn-group mdui-hidden-sm-down" buttons="@ViewBag.SelectedButtons"></module-buttons>

            <module-buttons class="mdui-hidden-md-up" buttons="@ViewBag.SelectedButtons" is-float="true"></module-buttons>

            <div class="mdui-toolbar-spacer"></div>
            <a class="eq-operate-cancel-select mdui-btn mdui-ripple" href="javascript:;">
                <i class="mdui-icon material-icons">do_not_disturb</i> 取消
            </a>
        </div>
    </div>
</div>
<div id="xd-appbar" class="mdui-appbar mdui-color-white mdui-shadow-1">
    <div class="mdui-toolbar">

        <a id="refreshBtn" class="eq-operate-cancel-select mdui-btn mdui-ripple mdui-ripple-black" href="javascript:;">
            <i class="mdui-icon material-icons">refresh</i> 刷新
        </a>
        <a id="ShaiXuan" class="mdui-btn mdui-ripple mdui-ripple-black" href="javascript:;">
            <i class="mdui-icon material-icons">keyboard_arrow_down</i> 筛选
        </a>
        <a id="reloadBtn" class="mdui-btn mdui-ripple mdui-ripple-black" href="javascript:;">
            <i class="mdui-icon material-icons">autorenew</i> 重置
        </a>

        <div class="mdui-toolbar-spacer"></div>


        <module-buttons class="mdui-btn-group" buttons="@ViewBag.InitialButtons"></module-buttons>


    </div>
</div>

<div class="mdui-dialog" id="ShaiXuanBox">
    <div class="mdui-container mdui-color-white">
        <div class="mdui-row ">
            <div class="mdui-col-xs-6">

                <div class="mdui-textfield">
                    <label class="mdui-textfield-label">账号类型</label>
                    <select class="mdui-textfield-input" id="userType" name="userType" asp-items="@Html.GetEnumSelectList(typeof(Eqwww.Domain.Models.Identity.UserType))">
                        <option value="">请选择</option>

                    </select>
                    <i class="mdui-icon material-icons" style="position:absolute;right:0;">arrow_drop_down</i>
                </div>
            </div>
            <div class="mdui-col-xs-6">
                <div class="mdui-textfield">
                    <label class="mdui-textfield-label">用户名/姓名关键字</label>
                    <input type="text" class="mdui-textfield-input" name="keyword" id="keyword" />
                </div>
            </div>
            
        </div>
        <div class="mdui-dialog-actions">
            <button class="mdui-btn mdui-text-color-theme mdui-ripple" id="searchBtn"><i class="mdui-icon material-icons">check</i> 确认</button>
            <button class="mdui-btn mdui-ripple" mdui-dialog-cancel><i class="mdui-icon material-icons">close</i> 取消</button>
        </div>
    </div>
</div>
<div class="mdui-container-fluid mdui-m-t-1">
    <div class="mdui-table-fluid">
        <table class="mdui-table" id="gridTable"></table>
        <div id="gridPager"></div>
    </div>
</div>


@section Scripts{
    <script>

        @{
            var s = Html.GetEnumSelectList(typeof(Eqwww.Domain.Models.Identity.UserType));
            var AddType= Html.GetEnumSelectList(typeof(Eqwww.Domain.Models.Identity.AddType));

        }
        var s = '@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(s))';
        var addType='@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(AddType))';
        var inst = new mdui.Dialog($('#ShaiXuanBox'));

        $(function () {



                $('#refreshBtn').bind('click', function () {
                    top.$.loading(false);
                    window.location.reload();
            });



            $('.eq-issystem-help').click(function () {
                top.$.snackbar('系统用户,不允许修改和删除.');
            });

            $('.eq-isdisabled-help').click(function () {
                top.$.snackbar('禁用用户将不能登录系统.');
            });

            $('.eq-pagination').find('a').bind('click', function () {
                top.$.loadingBox(false);
            });

            gridTable();
        });

        $('#ShaiXuan').click(function () {

            inst.open();
        })

        function gridTable() {
            var $gridList = $("#gridTable");
            $gridList.dataGrid({
                url: '/SystemManage/User/GridJson',
                mtype: "GET",
                styleUI: 'Bootstrap4',
                iconSet: 'fontAwesome',
                datatype: "json",
                sortname: 'CreateTime',
                sortorder: 'DESC',
                colModel: [
                    { label: 'Id', name: 'Id', key: true, hidden:true },
                    { label: '@Html.DisplayNameFor(x=>x.UserName)', name: 'UserName', width: 100 },
                    { label: '@Html.DisplayNameFor(x=>x.RealName)', name: 'RealName', width: 100 },
                    {
                        label: '@Html.DisplayNameFor(x=>x.UserType)', name: 'UserType', width: 100, formatter: function (cellValue) {
                            return $.GetEnumText(cellValue, s);
                        }
                    },
                    {
                        label: '@Html.DisplayNameFor(x=>x.AddType)', name: 'AddType', width: 100, formatter: function (cellValue) {
                            return $.GetEnumText(cellValue, addType);
                        }
                    },
                    {
                        label: '@Html.DisplayNameFor(x=>x.EmailConfirmed)', name: 'EmailConfirmed', width: 80, formatter: function (cellValue) {
                            return getBoolIcon(cellValue);
                        }
                    },
                    {
                        label: '@Html.DisplayNameFor(x=>x.IsSystem)', name: 'IsSystem', width: 80, formatter: function (cellValue) {
                            return getBoolIcon(cellValue);
                        }
                    },
                    {
                        label: '系统', name: 'IsSystem', hidden:true
                    },
                    {
                        label: '@Html.DisplayNameFor(x=>x.IsDisabled)', name: 'IsDisabled', width: 80, formatter: function (cellValue) {
                            return getBoolIcon(cellValue);
                        }
                    },
                    {
                        label: '@Html.DisplayNameFor(x=>x.CreateTime)', name: 'CreateTime', width: 110, formatter: 'date', formatoptions: {
                            srcformat:'Y-m-d', newformat:'Y-m-d'
                        }
                    }

                ],
                viewrecords: true,
                autowidth: true,
                height: getGridHeight()-36,
                rowNum: 20,
                pager: "#gridPager",
                shrinkToFit: true
            });

            $('#searchBtn').click(function () {
                $gridList.jqGrid('setGridParam', {
                    postData: {
                        keyword: $('#keyword').val(),
                        userType: $('#userType').val()
                    },
                }).trigger('reloadGrid');
                inst.close();
            });

            $('#reloadBtn').click(function () {
                $('#keyword').val('');
                $('#userType').val('');
                $gridList.jqGrid('setGridParam', {
                    postData: {
                        keyword: $('#keyword').val(),
                        userType: $('#userType').val()
                    },
                }).trigger('reloadGrid');
            })
        }

        function btn_create() {

            $.modalOpen({
                id: 'formCreate',
                title: '新建',
                url: '/SystemManage/User/Create',
                width: '100%',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
            return false;
        }

        function btn_edit() {
            //var key = $('.eq-list-table').GridSelectedKey();
            var key = $('#gridTable').jqGridRowValue().Id;
            var isSystem = $('#gridTable').jqGridRowValue().IsSystem;
            if (!key) {
                $.modalMessage('未选中任何行！');
                return false;
            }
            //alert(isSystem);
            if (isSystem == 'true') {
                top.$.errorLayer('系统用户不允许修改！');
                return false;
            }

            $.modalOpen({
                id: 'formEditButton',
                title: '修改',
                url: '/SystemManage/User/Edit?id=' + key,
                width: '100%',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }

        function btn_details() {
            var key = $('#gridTable').jqGridRowValue().Id;
            var isSystem = $('#gridTable').jqGridRowValue().IsSystem;
            if (!key) {
                $.modalMessage('未选中任何行！');
                return false;
            }
            $.modalOpen({
                id: 'Details',
                title: '查看',
                url: '/SystemManage/User/Details?id=' + key,
                width: '100%',
                height: '100%',
                isback: true,
                hideConfirmBtn: true,
                btn: null
            });
        }

        function btn_delete() {
            var key = $('#gridTable').jqGridRowValue().Id;
            var isSystem = $('#gridTable').jqGridRowValue().IsSystem;
            if (!key) {
                $.modalMessage('未选中任何行！');
                return false;
            }

            if (isSystem == 'true') {
                top.$.errorLayer('系统用户不允许移除！');
                return false;
            }

            $.deleteForm({
                url: '/SystemManage/User/Delete',
                param: { id: key },
                success: function () {
                    window.location.reload();
                }
            })
        }

        function btn_postrelation() {
            var key = $('#gridTable').jqGridRowValue().Id;
            var isSystem = $('#gridTable').jqGridRowValue().IsSystem;
            if (!key) {
                $.modalMessage('未选中任何行！');
                return false;
            }

            if (isSystem == 'true') {
                top.$.errorLayer('系统用户不允许修改！');
                return false;
            }

            $.modalOpen({
                id: 'formEditButton',
                title: '岗位调动',
                url: '/SystemManage/User/PostRelation?id=' + key,
                width: '100%',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }

        function btn_rolerelation() {
            var key = $('#gridTable').jqGridRowValue().Id;
            var isSystem = $('#gridTable').jqGridRowValue().IsSystem;
            if (!key) {
                $.modalMessage('未选中任何行！');
                return false;
            }

            //var isSystem = $('.eq-list-table').GridSelectedOptionValue('data-issystem');
            if (isSystem == 'true') {
                top.$.errorLayer('系统用户不允许修改！');
                return false;
            }

            $.modalOpen({
                id: 'formEditButton',
                title: '角色关联',
                url: '/SystemManage/User/RoleRelation?id=' + key,
                width: '100%',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }

        function btn_updateissystem() {
            var key = $('#gridTable').jqGridRowValue().Id;
            var isSystem = $('#gridTable').jqGridRowValue().IsSystem;
            if (!key) {
                top.$.snackbar('未选中任何行！');
                return false;
            }

            $.deleteForm({
                prompt:'确定提升为系统用户吗？',
                url: '/SystemManage/User/UpdateIsSystem',
                param: { id: key },
                success: function () {
                    window.location.reload();

                }
            })
        }

        function btn_updateisnotsystem() {
            var key = $('#gridTable').jqGridRowValue().Id;
            var isSystem = $('#gridTable').jqGridRowValue().IsSystem;
            if (!key) {
                top.$.snackbar('未选中任何行！');
                return false;
            }

            $.deleteForm({
                prompt: '确定取消系统用户吗？',
                url: '/SystemManage/User/UpdateIsNotSystem',
                param: { id: key },
                success: function () {
                    window.location.reload();

                }
            })
        }

        function btn_updatedisabled() {
            var key = $('#gridTable').jqGridRowValue().Id;
            var isSystem = $('#gridTable').jqGridRowValue().IsSystem;
            if (!key) {
                top.$.snackbar('未选中任何行！');
                return false;
            }

            //var isSystem = $('.eq-list-table').GridSelectedOptionValue('data-issystem');
            if (isSystem == 'true') {
                top.$.errorLayer('系统用户不允许修改！');
                return false;
            }

            $.deleteForm({
                prompt:'确定禁用用户吗？',
                url: '/SystemManage/User/UpdateDisabled',
                param: { userId: key },
                success: function () {
                    window.location.reload();

                }
            })
        }

        function btn_updateenabled() {
            var key = $('#gridTable').jqGridRowValue().Id;
            var isSystem = $('#gridTable').jqGridRowValue().IsSystem;
            if (!key) {
                top.$.snackbar('未选中任何行！');
                return false;
            }

            //var isSystem = $('.eq-list-table').GridSelectedOptionValue('data-issystem');
            if (isSystem == 'true') {
                top.$.errorLayer('系统用户不允许修改！');
                return false;
            }

            $.deleteForm({
                prompt:'确定启用用户吗？',
                url: '/SystemManage/User/UpdateEnabled',
                param: { userId: key },
                success: function () {
                    window.location.reload();

                }
            })
        }

    </script>
}
